#include <stdio.h>
#include <stdlib.h>
#include "sorts.h"
 
void shell_sort(ELE_TYPE arr[], int len)
{
	ELE_TYPE tmp;
	int first,i,j,step;
 
	step=len;
	do 
	{
		step= step /3 +1;
		for (first=0;first<step;first++)
		{
			for (i=first+step;i<len;i+=step)
			{
				tmp=arr[i];
				for (j=i-step;j>=first;j-=step)
				{
					if ( arr[j] <= tmp)
						break;
					arr[j+step]=arr[j];
				}
				arr[j+step]=tmp;
			}
		}
	}
	while (step>1);
}
 
void test_shell_sort()
{
	ELE_TYPE arr[] = { 61, 17, 29, 22, 34, 60, 72, 21, 50, 1, 62 };
	int len; 
 
	printf("Original data are:");
	len = (int) sizeof(arr) / sizeof(arr[0]);
	print_array(arr, len);
 
	shell_sort(arr, len);
	printf("The data after sorted are:");
	print_array(arr, len);	
	
	
}
